<?php

namespace Modules\Admin\Http\Controllers;

use HiCommon\Service\InsuranceService;
use Illuminate\Support\Facades\Request;

class InsuranceCompanyController extends BaseController
{
    /**
     *  保险公司 列表
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_index()
    {
        try {
            $res = InsuranceService::api_all_company();
            echo_error($res);
            return view('admin::insurance_company.company_index', ['arr_data'=>$res['data']]);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 保险公司-添加页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_add_page()
    {
        return view('admin::insurance_company.company_add_page');
    }

    /**
     * 保险公司-添加操作
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_add()
    {
        try {
            $arr_input = Request::input();
            return InsuranceService::api_add_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 保险公司-修改页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_edit_page()
    {
        try {
            $n_id = Request::get('id',0);
            $res = InsuranceService::api_find_one($n_id);
            echo_error($res);

            $arr_data = [
              'arr_data'=>$res['data'],
            ];
            return view('admin::insurance_company.company_edit_page',$arr_data);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 保险公司-修改操作
     *
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_edit()
    {
        try {
            $arr_input = Request::input();
            return InsuranceService::api_edit_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 保险公司-删除
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_delete()
    {
        try {
            $n_id = Request::get('id',0);
            return InsuranceService::api_delete_one($n_id);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 险种-添加页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_seed_add_page()
    {
        try {
            $n_id = Request::input('id');
            if($n_id <= 0){
                msg_error('操作id不能为空');
            }
            return view('admin::insurance_company.company_seed_add_page',['n_id'=>$n_id]);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 险种-添加操作
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_seed_add()
    {
        try {
            $arr_input = Request::input();
            return InsuranceService::api_seed_add_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    public function company_seed_edit_page(){
        try {
            $n_id = Request::get('id',0);
            $res = InsuranceService::api_seed_find_one($n_id);
            echo_error($res);

            $arr_data = [
              'arr_data'=>$res['data'],
            ];
            return view('admin::insurance_company.company_seed_edit_page',$arr_data);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    public function company_seed_edit(){
        try {
            $arr_input = Request::input();
            return InsuranceService::api_seed_edit_one($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    public function company_seed_delete(){
        try {
            $n_id = Request::get('id',0);
            return InsuranceService::api_seed_delete_one($n_id);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }


}
